const baseUrl = 'http://api-breakingnews-web.itheima.net'
let cropper = new Cropper($('#image')[0],{
    aspectRatio: 1,
    preview: $(".img-preview")
})

$('.select').on('click' , function (e) {
    e.preventDefault()
    $('#file').click()
})

$('#file').on('change', function (e) {
    const url = URL.createObjectURL(this.files[0])
    cropper.replace(url)
})




$('.sure').on('click' , function (e) {
    e.preventDefault()
    const canvas = cropper.getCroppedCanvas({
        width:100,
        height:100,
    })
    let base64Str =  canvas.toDataURL('image/jpeg')
    console.log(base64Str)
    base64Str = encodeURIComponent(base64Str)
    const dataStr = `avatar=${base64Str}`
    axios.post('http://api-breakingnews-web.itheima.net/my/update/avatar',dataStr,{headers: {
            Authorization: localStorage.getItem('token')
        }}).then(function (test) {

        window.parent._getuser()
    })
})